package com.bdc.activity;

import com.bdc.Var;
import com.bdc.R;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class LoginActivity extends Activity{
	
	private TextView userNameView;
	private TextView passwordView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		
		Button button = (Button) findViewById(R.id.loginButton);
		button.setOnClickListener(loginListener);
		
		userNameView = (TextView) findViewById(R.id.userName);
		passwordView = (TextView) findViewById(R.id.password);
	}
	
	private OnClickListener loginListener = new OnClickListener(){

		public void onClick(View v) {
			String userName = LoginActivity.this.userNameView.getText().toString();
			String password = LoginActivity.this.passwordView.getText().toString();
			
			SharedPreferences.Editor editor = LoginActivity.this.getSharedPreferences(Var.preference.file_name, MODE_PRIVATE).edit();
			editor.putString(Var.preference.user_name, userName);
			editor.putString(Var.preference.password, password);
			editor.commit();
			
			Intent intent = new Intent();
			intent.setClass(LoginActivity.this, MainActivity.class);
			startActivity(intent);
			finish();
		}	
	};

}
